home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Kool / Kool.jar / gamelib / Font.class (.txt) next >
Encoding:
Java Class File  |  2001-12-24  |  4.9 KB  |  104 lines

  1. package gamelib;
  2.  
  3. import javax.microedition.lcdui.Graphics;
  4. import javax.microedition.lcdui.Image;
  5.  
  6. public class Font {
  7.    public static byte[] data = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 48, 0, 0, 0, 19, 8, 0, 0, 0, 0, -13, 81, -47, -61, 0, 0, 0, 2, 98, 75, 71, 68, 0, -1, -121, -113, -52, -65, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, -59, 73, 68, 65, 84, 120, -38, -99, -110, -39, 14, -61, 48, 8, 4, 103, -83, -2, -1, 47, 79, 31, -64, 71, -46, 70, -86, -118, 99, 25, 7, 115, 45, 27, -127, 72, 75, 105, 1, -25, 45, 18, 91, 1, -64, 50, 94, -73, 46, 93, 85, 106, 33, -116, 108, 83, -57, -83, 20, -45, 61, -11, 9, 96, 100, 112, -105, -23, -104, -53, -49, 117, 27, -90, -115, -55, 62, -37, -17, 51, -40, -39, -17, 77, -78, 10, 12, -25, -101, 71, -121, 39, 25, 60, 103, 120, 18, 111, -112, -50, -74, -35, -53, -83, 15, -52, 117, 10, -79, -86, -10, -106, -50, -86, 126, 124, 67, -62, -115, -94, -85, -55, 24, 72, 59, -28, -40, 64, -78, 38, -74, -33, 118, -11, 71, -128, 31, 64, -53, 31, -80, -66, -26, -112, 98, -118, 1, 118, 61, -5, 100, 1, 3, -116, 100, 94, -12, 32, 68, 43, 39, -28, 105, 46, 109, -4, -66, -79, -86, -45, 20, 83, -110, 52, -67, -69, -19, 99, 96, 93, -60, 36, -65, 66, 80, 121, 17, -20, 108, -39, 44, -50, -82, 97, -99, 21, -7, 13, -18, 48, -117, -19, 13, 47, -54, -125, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
  8.    private static Image font;
  9.    private static byte[][] fontPos = new byte[][]{{0, 4, 8, 12, 16, 20, 24, 28, 32, 34, 37, 41, 43}, {0, 4, 8, 12, 16, 20, 24, 27, 31, 35, 41, 45}, {0, 4, 8, 10, 14, 18, 22, 26, 30, 34, 38, 42, 44}};
  10.    private static byte[][] fontSize = new byte[][]{{3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 3, 1, 5}, {3, 3, 3, 3, 3, 3, 2, 3, 3, 5, 3, 3}, {3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3}};
  11.    private static char[][] fontChars = new char[][]{{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'}, {'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y'}, {'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '-'}};
  12.    // $FF: renamed from: rx int
  13.    static int field_0;
  14.    static int row;
  15.    // $FF: renamed from: p int
  16.    static int field_1;
  17.    // $FF: renamed from: c char
  18.    static char field_2;
  19.  
  20.    private Font() {
  21.    }
  22.  
  23.    public static int drawString(Graphics g, String s, int x, int y) {
  24.       field_0 = x;
  25.       row = -1;
  26.       field_1 = 0;
  27.       field_2 = ' ';
  28.  
  29.       for(int i = 0; i < s.length(); ++i) {
  30.          field_2 = s.charAt(i);
  31.          if (field_2 == ' ') {
  32.             field_0 += 4;
  33.             row = -1;
  34.          } else if (field_2 >= fontChars[0][0] && field_2 <= fontChars[0][fontChars[0].length - 1]) {
  35.             row = 0;
  36.          } else if (field_2 >= fontChars[1][0] && field_2 <= fontChars[1][fontChars[1].length - 1]) {
  37.             row = 1;
  38.          } else {
  39.             row = 2;
  40.          }
  41.  
  42.          if (row >= 0) {
  43.             field_1 = getChar(field_2, row);
  44.             g.setClip(field_0, y, fontSize[row][field_1], 6);
  45.             g.drawImage(font, field_0 - fontPos[row][field_1], y - row * 7, 20);
  46.             field_0 += fontSize[row][field_1] + 1;
  47.          }
  48.       }
  49.  
  50.       return field_0;
  51.    }
  52.  
  53.    public static int stringWidth(String s) {
  54.       int rx = 0;
  55.       int row = -1;
  56.       int p = 0;
  57.       char c = ' ';
  58.  
  59.       for(int i = 0; i < s.length(); ++i) {
  60.          c = s.charAt(i);
  61.          if (c == ' ') {
  62.             rx += 4;
  63.             row = -1;
  64.          } else if (c >= fontChars[0][0] && c <= fontChars[0][fontChars[0].length - 1]) {
  65.             row = 0;
  66.          } else if (c >= fontChars[1][0] && c <= fontChars[1][fontChars[1].length - 1]) {
  67.             row = 1;
  68.          } else {
  69.             row = 2;
  70.          }
  71.  
  72.          if (row >= 0) {
  73.             p = getChar(c, row);
  74.             rx += fontSize[row][p] + 1;
  75.          }
  76.       }
  77.  
  78.       return rx;
  79.    }
  80.  
  81.    private static int getChar(char c, int row) {
  82.       for(int i = 0; i < fontChars[row].length; ++i) {
  83.          if (c == fontChars[row][i]) {
  84.             return i;
  85.          }
  86.       }
  87.  
  88.       return 0;
  89.    }
  90.  
  91.    static {
  92.       try {
  93.          font = Image.createImage(data, 0, data.length);
  94.       } catch (Exception ex) {
  95.          ((Throwable)ex).printStackTrace();
  96.       }
  97.  
  98.       field_0 = 0;
  99.       row = -1;
  100.       field_1 = 0;
  101.       field_2 = ' ';
  102.    }
  103. }
  104.